package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonErrorUnitListItemBean;
import com.fancy.learncenter.bean.CartoonUnitBean;
import com.fancy.learncenter.bean.CartoonUnitListBean;
import com.fancy.learncenter.common.JumpIntentKey;
import com.fancy.learncenter.ui.activity.CartoonErrorKindsActivity;
import com.fancy.learncenter.ui.activity.CartoonQuestionTypeActivity;
import com.fancy.learncenter.ui.activity.CartoonWorkQuestionTypeActivity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;

import java.util.List;

/**
 * Created by shiweiwei on 2018/1/18.
 */

public class CartoonErrorUnitListAdapter extends CommonRecycleViewAdapter<CartoonErrorUnitListItemBean> {
    JumpIntentKey.QUESTION_ENTER_TYPE type;
    Context mContext;

    public CartoonErrorUnitListAdapter(Context mContext, List<CartoonErrorUnitListItemBean> itemDatas, JumpIntentKey.QUESTION_ENTER_TYPE type) {
        super(mContext, R.layout.everyday_listen_speek_item, itemDatas);
        this.type = type;
        this.mContext = mContext;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final CartoonErrorUnitListItemBean item, int position) {

        TextView unit_num = customViewHold.getView(R.id.unit_num);
        TextView unit_text = customViewHold.getView(R.id.unit_text);

        if (!TextUtils.isEmpty(item.getUnitName())) {
            unit_text.setText(item.getUnitName());
            unit_num.setText(item.getUnitName());
        }
        ImageView lock_image = customViewHold.getView(R.id.lock_image);
        lock_image.setVisibility(View.GONE);
        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                switch (type) {
                    case HAS_CORRECTED:
                    case NOT_CORRECTED:
                        Intent intent = new Intent(mContext, CartoonWorkQuestionTypeActivity.class);
//                        Intent intent = new Intent(mContext, CartoonQuestionTypeActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable(JumpIntentKey.QUESTION_ENTER, type);
                        bundle.putString(JumpIntentKey.UNIT_ID, item.getUnitId());
                        bundle.putString(JumpIntentKey.HOMEWORK_PACKAGE_ID, item.getHomePackageId());
                        intent.putExtras(bundle);
                        mContext.startActivity(intent);
                        break;
                    case ERROR_KINDS:
                        Intent intentErrorKinds = new Intent(mContext, CartoonErrorKindsActivity.class);
                        Bundle bundleErrorKinds = new Bundle();
                        bundleErrorKinds.putSerializable(JumpIntentKey.QUESTION_ENTER, type);
                        bundleErrorKinds.putString(JumpIntentKey.UNIT_ID, item.getUnitId());
                        bundleErrorKinds.putString(JumpIntentKey.HOMEWORK_PACKAGE_ID, item.getHomePackageId());
                        intentErrorKinds.putExtras(bundleErrorKinds);
                        mContext.startActivity(intentErrorKinds);
                        break;
                }
            }
        });

    }
}
